export default class ZZCache {
  static saveToken(token) {
    window.localStorage.setItem('zz-juhaohuan-token', token);
  }

  static fetchToken() {
    return window.localStorage.getItem('zz-juhaohuan-token');
  }

  static clearToken() {
    window.localStorage.removeItem('zz-juhaohuan-token');
  }

  static saveUser(user) {
    window.localStorage.setItem('zz-juhaohuan-user', JSON.stringify(user));
  }

  static fetchUser() {
    const user = window.localStorage.getItem('zz-juhaohuan-user');
    if (user) {
      return JSON.parse(user);
    } else {
      return null;
    }
  }

  static clearUser() {
    window.localStorage.removeItem('zz-juhaohuan-user');
  }

  static saveSmsTime() {
    window.localStorage.setItem('zz-juhaohuan-sms', new Date().getTime().toString());
  }

  static fetchSmsTime() {
    const ms = window.localStorage.getItem('zz-juhaohuan-sms');
    if (!ms) return null;
    else return Number(ms);
  }
}
